/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   Module Name          : com.yaodian100.mall.index.web.IndexAction
   Module Description   :

   Date Created      : 2010/1/21
   Original Author   : feeling.wang
   Team              : yaodian100
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   MODIFICATION HISTORY
   ------------------------------------------------------------------------------
   Date Modified       Modified by       Comments
   ------------------------------------------------------------------------------
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
package com.yaodian100.mall.index.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.yaodian100.core.common.utils.ServerValue;
import com.yaodian100.mall.member.util.UserData;

/**
 * @author feeling.wang
 * 
 */
public class IndexAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 7535627921425193375L;
	/* tiles 參數 */
	private String pageDescription;
	private String pageTitle;
	private String pageKeywords;

	public String getPageDescription() {
		return pageDescription;
	}

	public String getPageKeywords() {
		return pageKeywords;
	}

	public String getPageTitle() {
		return pageTitle;
	}

	/**
	 * 用於判斷是否處於首頁，目前有 categorynav 會用到
	 */
	public boolean isInIndexPage() {
		return true;
	}

	public String index() {
		pageDescription = ServerValue.getSeoProp().getProperty("index.description");
		pageKeywords = ServerValue.getSeoProp().getProperty("index.keywords");
		pageTitle = ServerValue.getSeoProp().getProperty("index.title");
		// 清除cookie product、category
		HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
		HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(
				ServletActionContext.HTTP_RESPONSE);
		UserData userData = new UserData(request, response);
		userData.clear("fromCategory");
		userData.clear("fromProduct");
		if (StringUtils.isBlank(userData.readRawValue(UserData.NAME_YAODIAN100_CART_ITEMS))) {
			userData.writeRawValue(UserData.NAME_YAODIAN100_CART_ITEMS, "0");
		}
		return "index";
	}

	public void setPageDescription(String pageDescription) {
		this.pageDescription = pageDescription;
	}

	public void setPageKeywords(String pageKeywords) {
		this.pageKeywords = pageKeywords;
	}

	public void setPageTitle(String pageTitle) {
		this.pageTitle = pageTitle;
	}
}
